class Plant {
  final String id;
  final String image;
  final Map<String, String> image_list;
  final String name;
  final String water_day;
  final String? create_time;

  Plant({
    required this.id,
    required this.image,
    required this.image_list,
    required this.name,
    required this.water_day,
    this.create_time,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'image': image,
      'imageList': image_list,
      'name': name,
      'waterDay': water_day,
      'createTime': create_time,
    };
  }

  factory Plant.fromJson(Map<String, dynamic> json) {
    String image = json['image'] as String;
    Map<String, dynamic> raw_image_list =
        json['imageList'] as Map<String, dynamic>;
    Map<String, String> converted_image_list = raw_image_list.map(
      (key, value) => MapEntry(key, value.toString()),
    );

    return Plant(
      id: json['id'] as String,
      image: image,
      image_list: converted_image_list,
      name: json['name'] as String,
      water_day: json['waterDay'] as String,
      create_time: json['createTime'] as String?,
    );
  }

  Plant copyWith({
    String? id,
    String? image,
    Map<String, String>? image_list,
    String? name,
    String? water_day,
    String? create_time,
  }) {
    return Plant(
      id: id ?? this.id,
      image: image ?? this.image,
      image_list: image_list ?? this.image_list,
      name: name ?? this.name,
      water_day: water_day ?? this.water_day,
      create_time: create_time ?? this.create_time,
    );
  }

  @override
  String toString() {
    return 'Plant(id: $id, image: $image, image_list: $image_list, name: $name, water_day: $water_day, create_time: $create_time)';
  }
}

class PlantModel {
  final String id;
  final String name;
  final String species;
  final String image_url;
  final String water_frequency;

  PlantModel({
    required this.id,
    required this.name,
    required this.species,
    required this.image_url,
    required this.water_frequency,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'species': species,
      'imageUrl': image_url,
      'waterFrequency': water_frequency,
    };
  }

  factory PlantModel.fromJson(Map<String, dynamic> json) {
    return PlantModel(
      id: json['id'] as String,
      name: json['name'] as String,
      species: json['species'] as String,
      image_url: json['imageUrl'] as String,
      water_frequency: json['waterFrequency'] as String,
    );
  }

  PlantModel copyWith({
    String? id,
    String? name,
    String? species,
    String? image_url,
    String? water_frequency,
  }) {
    return PlantModel(
      id: id ?? this.id,
      name: name ?? this.name,
      species: species ?? this.species,
      image_url: image_url ?? this.image_url,
      water_frequency: water_frequency ?? this.water_frequency,
    );
  }

  @override
  String toString() {
    return 'PlantModel(id: $id, name: $name, species: $species, image_url: $image_url, water_frequency: $water_frequency)';
  }
}
